package com.xxl.job.admin.dao.impl;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ibm.risk.common.dao.JpaDAO;
import com.xxl.job.admin.core.model.JobLogGlue;
import com.xxl.job.admin.dao.IJobLogGlueDao;

/**
 * job log for glue
 * @author xuxueli 2016-5-19 18:17:52
 */
@Repository
@Transactional(readOnly = true)
public class JobLogGlueDaoImpl implements IJobLogGlueDao {

	@Inject
	JpaDAO dao;
	
	@Override
	@Transactional(readOnly = false)
	public int save(JobLogGlue jobLogGlue) {
		dao.persist(jobLogGlue);
		return 1;
	}

	@Override
	public List<JobLogGlue> findByJobId(Long jobId) {
		return dao.createNamedQuery(JobLogGlue.QUERY_BY_JOB_ID, JobLogGlue.class).setParameter("jobId", jobId).getResultList();
	}

	@Override
	@Transactional(readOnly = false)
	public int removeOld(Long jobId, int limit) {
		// HashMap<String, Object> params = new HashMap<String, Object>();
		// params.put("jobId", jobId);
		// params.put("limit", limit);
		// return sqlSessionTemplate.delete("XxlJobLogGlueMapper.removeOld", params);
		return 0;
	}

	@Override
	@Transactional(readOnly = false)
	public int deleteByJobId(Long jobId) {
		return dao.createNamedQuery(JobLogGlue.DEL_BY_JOB_ID).setParameter("jobId", jobId).executeUpdate();
	}
	
}
